$(function() {
    $.put = function(url, cb) {
        $.ajax({url: url, type: 'PUT', }).done(cb)
    }
    // 全局
    var tid = location.pathname
    //-----------------------------
    // 2.2.1.   基本信息
    function cb_tid_info(data) {
        // console.log('tid_info', data)
        $('#name').val(data.name)
        $('#tags').text(data.tags.join(', '))
        $('#dever').text(data.dever)
        $('#initVer').text(data.initVer)
        $('#stableVer').text(data.stableVer)
        $('#devStat').text(data.devStat)
        $('#codeLangs').text(data.codeLangs)
        $('#os').text(data.os)
        $('#type').text(data.type)
        $('#license').text(data.license)
    }
    $.get(tid + '/info', cb_tid_info)
    // 2.2.2.   基本信息-刷新
    $('#tid_info_fress').click(function() {
        $.put(tid + '/info', cb_tid_info)
    })
    // 2.2.3.   基本信息-更新
    $('#tid_info_update').click(function() {
        $.post(tid + '/info', {
            name: $('#name').val().trim(),
            tags: $('#tags').text().trim(),
            dever: $('#dever').text().trim(),
            initVer: $('#initVer').text().trim(),
            stableVer: $('#stableVer').text().trim(),
            devStat: $('#devStat').text().trim(),
            codeLangs: $('#codeLangs').text().trim(),
            os: $('#os').text().trim(),
            type: $('#type').text().trim(),
            license: $('#license').text().trim()
        }, function(data) {
            console.log(data)
        })
    })
    //-----------------------------
    // 2.3.1.    社区信息
    function cb_community_info(data) {
        // console.log('community_info', data)
        $('#commits').text(data.commits)
        $('#contributors').text(data.contributors)
        $('#branches').text(data.branches)
        $('#releases').text(data.releases)
    }
    $.get(tid + '/community/info', cb_community_info)
    // 2.3.2.   社区信息-刷新
    $('#community_info_fresh').click(function() {
        $.put(tid + '/community/info', cb_community_info)
    })
    // 2.3.3.   日期-提交数-贡献者
    function cb_commits_contributors(data) {
        // console.log('commits_contributors', data)
        render_commits_contributors(data)
    }
    $.get(tid + '/community/commits_contributors', cb_commits_contributors)
    $('#commits_contributors_fresh').click(function() {
        $.put(tid + '/community/commits_contributors', cb_commits_contributors)
    })
    // 2.3.4.   贡献者等级
    function cb_contributors_level(data) {
        // console.log('contributors_level', data)
        render_contributors_level(data)
    }
    $.get(tid + '/community/contributors_level', cb_contributors_level)
    $('#contributors_level_fresh').click(function() {
        $.put(tid + '/community/contributors_level', cb_contributors_level)
    })
    //-----------------------------
    // 2.4.1.   关注度信息
    function cb_activity_info(data) {
        // console.log('activity_info', data)
        $('#last30day').text(data.last30day)
        $('#last12month').text(data.last12month)
    }
    $.get(tid + '/activity/info', cb_activity_info)
    $('#activity_info_fresh').click(function() {
        $.put(tid + '/activity/info', cb_activity_info)
    })
    // 2.4.2.   项目关注情况
    function cb_activity_git_stat(data) {
        // console.log('activity_git_stat', data)
        render_activity_git_stat(data)
    }
    $.get(tid + '/activity/git_stat', cb_activity_git_stat)
    $('#activity_git_stat_fresh').click(function() {
        $.put(tid + '/activity/git_stat', cb_activity_git_stat)
    })
    // 2.4.3.   项目需求情况
    function cb_activity_git_pull(data) {
        // console.log('activity_git_pull', data)
        render_activity_git_pull(data)
    }
    $.get(tid + '/activity/git_pull', cb_activity_git_pull)
    $('#activity_git_pull_fresh').click(function() {
        $.put(tid + '/activity/git_pull', cb_activity_git_pull)
    })
    // 2.4.4.   项目讨论情况
    function cb_activity_git_issues(data) {
        // console.log('activity_git_issues', data)
        render_activity_git_issues(data)
    }
    $.get(tid + '/activity/git_issues', cb_activity_git_issues)
    $('#activity_git_issues_fresh').click(function() {
        $.put(tid + '/activity/git_issues', cb_activity_git_issues)
    })
    // 2.4.5.   博客类
    function cb_activity_blogs(data) {
        // console.log('activity_blogs', data)
        render_activity_blogs(data)
    }
    $.get(tid + '/activity/blogs', cb_activity_blogs)
    $('#activity_blogs_fresh').click(function() {
        $.put(tid + '/activity/blogs', cb_activity_blogs)
    })
    // 2.4.6.   论坛类
    function cb_activity_bbs(data) {
        // console.log('activity_bbs', data)
        render_activity_bbs(data)
    }
    $.get(tid + '/activity/bbs', cb_activity_bbs)
    $('#activity_bbs_fresh').click(function() {
        $.put(tid + '/activity/bbs', cb_activity_bbs)
    })
    // 2.4.7.   书籍类
    function cb_activity_books(data) {
        // console.log('activity_books', data)
        render_activity_books(data)
    }
    $.get(tid + '/activity/books', cb_activity_books)
    $('#activity_books_fresh').click(function() {
        $.put(tid + '/activity/books', cb_activity_books)
    })
    // 2.4.8.   搜索类
    function cb_activity_searchs(data) {
        // console.log('activity_searchs', data)
        render_activity_searchs(data)
    }
    $.get(tid + '/activity/searchs', cb_activity_searchs)
    $('#activity_searchs_fresh').click(function() {
        $.put(tid + '/activity/searchs', cb_activity_searchs)
    })
    //-----------------------------
    // 2.5.1.   最新版代码信息
    function cb_code_info(data) {
        // console.log('code_info', data)
        $('#lines').text(data.lines)
        $('#languages').text(data.languages)
        $('#codes').text(data.codes)
        $('#comments').text(data.comments)
        $('#blanks').text(data.blanks)
        $('#pcode').text(data.pcode)
        $('#pcomment').text(data.pcomment)
        $('#pblank').text(data.pblank)
        render_code_info(data)
    }
    $.get(tid + '/code/info', cb_code_info)
    $('#code_info_fresh').click(function() {
        $.put(tid + '/code/info', cb_code_info)
    })
    // 2.5.2.   最新版语言占比
    function cb_code_languages(data) {
        // console.log('code_languages', data)
        render_code_languages(data)
    }
    $.get(tid + '/code/languages', cb_code_languages)
    $('#code_languages_fresh').click(function() {
        $.put(tid + '/code/languages', cb_code_languages)
    })
    // 2.5.3.   日期-代码/注释/空行
    function cb_code_by_date(data) {
        // console.log('code_by_date', data)
        render_code_by_date(data)
    }
    $.get(tid + '/code/by_date', cb_code_by_date)
    $('#code_by_date_fresh').click(function() {
        $.put(tid + '/code/by_date', cb_code_by_date)
    })
    // 2.5.4.   版本-代码行数
    function cb_code_by_tag(data) {
        // console.log('code_by_tag', data)
        render_code_by_tag(data)
    }
    $.get(tid + '/code/by_tag', cb_code_by_tag)
    $('#code_by_tag_fresh').click(function() {
        $.put(tid + '/code/by_tag', cb_code_by_tag)
    })
    //-----------------------------
    // 2.6.1.   漏洞信息
    function cb_security_info(data) {
        // console.log('security_info', data)
        render_security_info(data)
        render_security_level(data)
        render_security_list(data)
    }
    $.get(tid + '/security/info', cb_security_info)
    $('#security_info_fresh').click(function() {
        $.put(tid + '/security/info', cb_security_info)
    })
})